<?php
/**
 * Created by PhpStorm.
 * User: cxj
 * Date: 16/12/26
 * Time: 下午2:59
 */
use app\assets\AppAsset;
$baseUrl = Yii::$app->request->baseUrl;
AppAsset::addCss($this, $baseUrl . "/css/activity.css");
AppAsset::addCss($this, $baseUrl . "/css/kkpager_orange.css");
AppAsset::addScript($this, $baseUrl . "/js/kkpager.min.js");
?>
<div class="head">
    <div class="title">全部活动</div>
    <div style="float: right;position: relative;top: -30px;">
        <span class="my-font">我的账单</span>
        <span class="my-font" id="publish"><a style="display: inline-block;text-decoration: none;cursor: pointer;color: #000">创建活动</a></span>
        <img src="../../img/head.jpeg" style="width: 40px;height: auto;margin-right: 15px">
        <span class="my-font" >退出</span>
    </div>
</div>
<div class="status-div">
    <div class="un-finish" onClick=myClick1(0)>全部</div>
    <div class="un-finish" onClick=myClick1(1)>未发布</div>
    <div class="un-finish" style="position:relative;top:-7px" onClick=myClick1(2)>进行中</div>
    <div class="done" style="position:relative;top:-7px" onClick=myClick1(3)>已结束</div>
</div>
<div class="activity-content">

</div>

<div style="width:800px;margin:0 auto;">
    <div id="kkpager" class="kkpager">
    </div>
</div>
<script>
//    var activity = JSON.stringify(<?//= $activities ?>//);
    var s = <?= $status ?>;
    console.log(s);
    function getParameter(name) {
        var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r!=null) return unescape(r[2]); return null;
    }

    //init
    $(function(){
        var totalPage = <?= $pageSize ?>;
        var totalRecords = <?= $total ?>;
        var pageNo = getParameter('pno');
        if(!pageNo){
            pageNo = 1;
        }
        $.ajax({
            type:'post',
            url:'get-activity',
            data:{
                'pageNum':1,'status':s
            },
            dataType:'json',
            success:function(data){
                console.log('初始',data);
                for(var i= 0,l=data.length;i<l;i++){
                    console.log('nihao',data[i].id);
                    if(data[i].status==1){
                        $(".activity-content").append(
                            "<ul> " +
                            "<li class='activity'> " +
                            "<div class=\"status\"><div>未发布</div></div>" +
                            "<div class='poster'><img src='../../img/gc-icon.jpeg' style='width: 206px;height: 160px;margin-top: 20px'></div> " +
                            "<div class='detail'>" +
                            "<h3>"+ data[i]._title+"</h3>" +
                            "<div class='property'>" +
                            "<div class='time'>" +
                            "<label>时间:</label>" +
                            "<span style='margin-left: 10px'>"+ data[i].start_time +"<span/>" +
                            "</div>"+
                            "<div class='time'>" +
                            "<label>地点:</label>" +
                            "<span style='margin-left: 10px'>"+ data[i].city+" "+data[i].address +"<span/>" +
                            "</div>"+
                            "<div class='time'>" +
                            "<span>" +
                            "<label>收藏:</label>" +
                            "<span style='margin-left: 10px'>0<span/>" +
                            "</span>"+
                            "<span>" +
                            "<label>报名:</label>" +
                            "<span style='margin-left: 10px'>0<span/>" +
                            "</span>"+
                            "<span>" +
                            "<label>签到:</label>" +
                            "<span style='margin-left: 10px'>0<span/>" +
                            "</span>"+
                            "</div>"+
                            "</div>"+
                            "<div class='flow'>" +
                            "<button class='btn btn-default my-btn' onclick='publish("+data[i].id+")'>发布</button>"+
                            "<span class='btn btn-default my-btn' style='background-color: #eee'>报名签到管理</span>"+
                            "</div>"+
                            "</div>" +
                            "<div class='operation'>" +
                            "<ul> " +
                            "<li> " +
                            "<a onclick='deleteActivity("+data[i].id+")'>删除" +
                            "</a> " +
                            "</li> " +
                            "<li> " +
                            "<a href='edit?id="+data[i].id+"'>编辑" +
                            "</a> " +
                            "</li> " +
                            "<li> " +
                            "<a href='delete?id="+data[i].id+"'>分享" +
                            "</a> " +
                            "</li> " +

                            "</ul> " +
                            "</div>"+
                            "</li> "+
                            "</ul>")
                    }else if(data[i].status==2){
                        data[i].status = '进行中';
                        $(".activity-content").append(
                            "<ul> " +
                            "<li class='activity'> " +
                            "<div class=\"status\"><div>"+data[i].status+"</div></div>" +
                            "<div class='poster'><img src='../../img/gc-icon.jpeg' style='width: 206px;height: 160px;margin-top: 20px'></div> " +
                            "<div class='detail'>" +
                            "<h3>"+ data[i]._title+"</h3>" +
                            "<div class='property'>" +
                            "<div class='time'>" +
                            "<label>时间:</label>" +
                            "<span style='margin-left: 10px'>"+ data[i].start_time +"<span/>" +
                            "</div>"+
                            "<div class='time'>" +
                            "<label>地点:</label>" +
                            "<span style='margin-left: 10px'>"+ data[i].city+" "+data[i].address +"<span/>" +
                            "</div>"+
                            "<div class='time'>" +
                            "<span>" +
                            "<label>收藏:</label>" +
                            "<span style='margin-left: 10px'>0<span/>" +
                            "</span>"+
                            "<span>" +
                            "<label>报名:</label>" +
                            "<span style='margin-left: 10px'>0<span/>" +
                            "</span>"+
                            "<span>" +
                            "<label>签到:</label>" +
                            "<span style='margin-left: 10px'>0<span/>" +
                            "</span>"+
                            "</div>"+
                            "</div>"+
                            "<div class='flow'>" +
                            "<button class='btn btn-default my-btn' onclick='cancelPublish("+data[i].id+")'>取消发布</button>"+
                            "<button class='btn btn-default my-btn' onclick='signIn()'>报名签到管理</button>"+
                            "</div>"+
                            "</div>" +
                            "<div class='operation'>" +
                            "<ul> " +
                            "<li> " +
                            "<a onclick='deleteActivity("+data[i].id+")'>删除" +
                            "</a> " +
                            "</li> " +
                            "<li> " +
                            "<a href='edit?id="+data[i].id+"'>编辑" +
                            "</a> " +
                            "</li> " +
                            "<li> " +
                            "<a href='delete?id="+data[i].id+"'>分享" +
                            "</a> " +
                            "</li> " +

                            "</ul> " +
                            "</div>"+
                            "</li> "+
                            "</ul>")
                    }else if(data[i].status==3){
                        data[i].status = '已结束';
                        $(".activity-content").append(
                            "<ul> " +
                            "<li class='activity'> " +
                            "<div class=\"status\"><div>"+data[i].status+"</div></div>" +
                            "<div class='poster'><img src='../../img/gc-icon.jpeg' style='width: 206px;height: 160px;margin-top: 20px'></div> " +
                            "<div class='detail'>" +
                            "<h3>"+ data[i]._title+"</h3>" +
                            "<div class='property'>" +
                            "<div class='time'>" +
                            "<label>时间:</label>" +
                            "<span style='margin-left: 10px'>"+ data[i].start_time +"<span/>" +
                            "</div>"+
                            "<div class='time'>" +
                            "<label>地点:</label>" +
                            "<span style='margin-left: 10px'>"+ data[i].city+" "+data[i].address +"<span/>" +
                            "</div>"+
                            "<div class='time'>" +
                            "<span>" +
                            "<label>收藏:</label>" +
                            "<span style='margin-left: 10px'>0<span/>" +
                            "</span>"+
                            "<span>" +
                            "<label>报名:</label>" +
                            "<span style='margin-left: 10px'>0<span/>" +
                            "</span>"+
                            "<span>" +
                            "<label>签到:</label>" +
                            "<span style='margin-left: 10px'>0<span/>" +
                            "</span>"+
                            "</div>"+
                            "</div>"+
                            "<div class='flow'>" +
                            "<button class='btn btn-default my-btn' style='background-color: #eee'>取消发布</button>"+
                            "<button class='btn btn-default my-btn' onclick='signIn()'>报名签到管理</button>"+
                            "</div>"+
                            "</div>" +
                            "<div class='operation'>" +
                            "<ul> " +
                            "<li> " +
                            "<a onclick='deleteActivity("+data[i].id+")'>删除" +
                            "</a> " +
                            "</li> " +
                            "<li> " +
                            "<a href='edit?id="+data[i].id+"'>编辑" +
                            "</a> " +
                            "</li> " +
                            "<li> " +
                            "<a href='delete?id="+data[i].id+"'>分享" +
                            "</a> " +
                            "</li> " +

                            "</ul> " +
                            "</div>"+
                            "</li> "+
                            "</ul>")
                    }
//                    $(".activity-content").append(
//                        "<ul> " +
//                            "<li class='activity'> " +
//                                "<div class=\"status\"><div>"+data[i].status+"</div></div>" +
//                                "<div class='poster'><img src='../../img/gc-icon.jpeg' style='width: 206px;height: 160px;margin-top: 20px'></div> " +
//                                "<div class='detail'>" +
//                                    "<h3>"+ data[i]._title+"</h3>" +
//                                    "<div class='property'>" +
//                                        "<div class='time'>" +
//                                            "<label>时间:</label>" +
//                                            "<span style='margin-left: 10px'>"+ data[i].start_time +"<span/>" +
//                                        "</div>"+
//                                        "<div class='time'>" +
//                                            "<label>地点:</label>" +
//                                            "<span style='margin-left: 10px'>"+ data[i].city+" "+data[i].address +"<span/>" +
//                                        "</div>"+
//                                        "<div class='time'>" +
//                                            "<span>" +
//                                                "<label>收藏:</label>" +
//                                                "<span style='margin-left: 10px'>0<span/>" +
//                                            "</span>"+
//                                            "<span>" +
//                                                "<label>报名:</label>" +
//                                                "<span style='margin-left: 10px'>0<span/>" +
//                                            "</span>"+
//                                            "<span>" +
//                                                "<label>签到:</label>" +
//                                                "<span style='margin-left: 10px'>0<span/>" +
//                                            "</span>"+
//                                        "</div>"+
//                                    "</div>"+
//                                    "<div class='flow'>" +
//                                        "<button class='btn btn-default my-btn'>取消发布</button>"+
//                                        "<button class='btn btn-default my-btn'>报名签到管理</button>"+
//                                    "</div>"+
//                                "</div>" +
//                                "<div class='operation'>" +
//                                    "<ul> " +
//                                        "<li> " +
//                                            "<a onclick='deleteActivity("+data[i].id+")'>删除" +
//                                            "</a> " +
//                                        "</li> " +
//                                        "<li> " +
//                                            "<a href='edit?id="+data[i].id+"'>编辑" +
//                                            "</a> " +
//                                        "</li> " +
//                                        "<li> " +
//                                            "<a href='delete?id="+data[i].id+"'>分享" +
//                                            "</a> " +
//                                        "</li> " +
//
//                                    "</ul> " +
//                                "</div>"+
//                            "</li> "+
//                        "</ul>")
                }
            }
        });

        //生成分页
        //有些参数是可选的，比如lang，若不传有默认值
        kkpager.generPageHtml({
            pno : pageNo,//当前页数
            //总页码
            total : totalPage,
            //总数据条数
            totalRecords : totalRecords,//总数据条数
            mode : 'click',//默认值是link，可选link或者click
            click : function(n){
                // do something
                //手动选中按钮
                console.log('nnn',n);
                $(".activity-content").html("");
                $.ajax({
                    type:'post',
                    url:'get-activity',
                    data:{
                        'pageNum':n,
                        'status':s
                    },
                    dataType:'json',
                    success:function(data){
                        for(var i= 0,l=data.length;i<l;i++){
                            console.log('oooo',data[i].id);
                            console.log('status',data[i].status);
                            if(data[i].status==1){
                                data[i].status = '未发布';
                                $(".activity-content").append(
                                    "<ul> " +
                                    "<li class='activity'> " +
                                    "<div class=\"status\"><div>未发布</div></div>" +
                                    "<div class='poster'><img src='../../img/gc-icon.jpeg' style='width: 206px;height: 160px;margin-top: 20px'></div> " +
                                    "<div class='detail'>" +
                                    "<h3>"+ data[i]._title+"</h3>" +
                                    "<div class='property'>" +
                                    "<div class='time'>" +
                                    "<label>时间:</label>" +
                                    "<span style='margin-left: 10px'>"+ data[i].start_time +"<span/>" +
                                    "</div>"+
                                    "<div class='time'>" +
                                    "<label>地点:</label>" +
                                    "<span style='margin-left: 10px'>"+ data[i].city+" "+data[i].address +"<span/>" +
                                    "</div>"+
                                    "<div class='time'>" +
                                    "<span>" +
                                    "<label>收藏:</label>" +
                                    "<span style='margin-left: 10px'>0<span/>" +
                                    "</span>"+
                                    "<span>" +
                                    "<label>报名:</label>" +
                                    "<span style='margin-left: 10px'>0<span/>" +
                                    "</span>"+
                                    "<span>" +
                                    "<label>签到:</label>" +
                                    "<span style='margin-left: 10px'>0<span/>" +
                                    "</span>"+
                                    "</div>"+
                                    "</div>"+
                                    "<div class='flow'>" +
                                    "<button class='btn btn-default my-btn' onclick='publish("+data[i].id+")'>发布</button>"+
                                    "<span class='btn btn-default my-btn' style='background-color: #eee'>报名签到管理</span>"+
                                    "</div>"+
                                    "</div>" +
                                    "<div class='operation'>" +
                                    "<ul> " +
                                    "<li> " +
                                    "<a onclick='deleteActivity("+data[i].id+")'>删除" +
                                    "</a> " +
                                    "</li> " +
                                    "<li> " +
                                    "<a href='edit?id="+data[i].id+"'>编辑" +
                                    "</a> " +
                                    "</li> " +
                                    "<li> " +
                                    "<a href='delete?id="+data[i].id+"'>分享" +
                                    "</a> " +
                                    "</li> " +

                                    "</ul> " +
                                    "</div>"+
                                    "</li> "+
                                    "</ul>")
                            }else if(data[i].status==2){
                                data[i].status = '进行中';
                                $(".activity-content").append(
                                    "<ul> " +
                                    "<li class='activity'> " +
                                    "<div class=\"status\"><div>"+data[i].status+"</div></div>" +
                                    "<div class='poster'><img src='../../img/gc-icon.jpeg' style='width: 206px;height: 160px;margin-top: 20px'></div> " +
                                    "<div class='detail'>" +
                                    "<h3>"+ data[i]._title+"</h3>" +
                                    "<div class='property'>" +
                                    "<div class='time'>" +
                                    "<label>时间:</label>" +
                                    "<span style='margin-left: 10px'>"+ data[i].start_time +"<span/>" +
                                    "</div>"+
                                    "<div class='time'>" +
                                    "<label>地点:</label>" +
                                    "<span style='margin-left: 10px'>"+ data[i].city+" "+data[i].address +"<span/>" +
                                    "</div>"+
                                    "<div class='time'>" +
                                    "<span>" +
                                    "<label>收藏:</label>" +
                                    "<span style='margin-left: 10px'>0<span/>" +
                                    "</span>"+
                                    "<span>" +
                                    "<label>报名:</label>" +
                                    "<span style='margin-left: 10px'>0<span/>" +
                                    "</span>"+
                                    "<span>" +
                                    "<label>签到:</label>" +
                                    "<span style='margin-left: 10px'>0<span/>" +
                                    "</span>"+
                                    "</div>"+
                                    "</div>"+
                                    "<div class='flow'>" +
                                    "<button class='btn btn-default my-btn' onclick='cancelPublish("+data[i].id+")'>取消发布</button>"+
                                    "<button class='btn btn-default my-btn' onclick='signIn()'>报名签到管理</button>"+
                                    "</div>"+
                                    "</div>" +
                                    "<div class='operation'>" +
                                    "<ul> " +
                                    "<li> " +
                                    "<a onclick='deleteActivity("+data[i].id+")'>删除" +
                                    "</a> " +
                                    "</li> " +
                                    "<li> " +
                                    "<a href='edit?id="+data[i].id+"'>编辑" +
                                    "</a> " +
                                    "</li> " +
                                    "<li> " +
                                    "<a href='delete?id="+data[i].id+"'>分享" +
                                    "</a> " +
                                    "</li> " +

                                    "</ul> " +
                                    "</div>"+
                                    "</li> "+
                                    "</ul>")
                            }else if(data[i].status==3){
                                data[i].status = '已结束';
                                $(".activity-content").append(
                                    "<ul> " +
                                    "<li class='activity'> " +
                                    "<div class=\"status\"><div>"+data[i].status+"</div></div>" +
                                    "<div class='poster'><img src='../../img/gc-icon.jpeg' style='width: 206px;height: 160px;margin-top: 20px'></div> " +
                                    "<div class='detail'>" +
                                    "<h3>"+ data[i]._title+"</h3>" +
                                    "<div class='property'>" +
                                    "<div class='time'>" +
                                    "<label>时间:</label>" +
                                    "<span style='margin-left: 10px'>"+ data[i].start_time +"<span/>" +
                                    "</div>"+
                                    "<div class='time'>" +
                                    "<label>地点:</label>" +
                                    "<span style='margin-left: 10px'>"+ data[i].city+" "+data[i].address +"<span/>" +
                                    "</div>"+
                                    "<div class='time'>" +
                                    "<span>" +
                                    "<label>收藏:</label>" +
                                    "<span style='margin-left: 10px'>0<span/>" +
                                    "</span>"+
                                    "<span>" +
                                    "<label>报名:</label>" +
                                    "<span style='margin-left: 10px'>0<span/>" +
                                    "</span>"+
                                    "<span>" +
                                    "<label>签到:</label>" +
                                    "<span style='margin-left: 10px'>0<span/>" +
                                    "</span>"+
                                    "</div>"+
                                    "</div>"+
                                    "<div class='flow'>" +
                                    "<button class='btn btn-default my-btn' style='background-color: #eee'>取消发布</button>"+
                                    "<button class='btn btn-default my-btn' onclick='signIn()'>报名签到管理</button>"+
                                    "</div>"+
                                    "</div>" +
                                    "<div class='operation'>" +
                                    "<ul> " +
                                    "<li> " +
                                    "<a onclick='deleteActivity("+data[i].id+")'>删除" +
                                    "</a> " +
                                    "</li> " +
                                    "<li> " +
                                    "<a href='edit?id="+data[i].id+"'>编辑" +
                                    "</a> " +
                                    "</li> " +
                                    "<li> " +
                                    "<a href='delete?id="+data[i].id+"'>分享" +
                                    "</a> " +
                                    "</li> " +

                                    "</ul> " +
                                    "</div>"+
                                    "</li> "+
                                    "</ul>")
                            }

                        }
                    }
                });



                this.selectPage(n);

                //return false;
            },

            lang: {
                firstPageText			: '首页',
                firstPageTipText		: '首页',
                lastPageText			: '尾页',
                lastPageTipText			: '尾页',
                prePageText				: '上一页',
                prePageTipText			: '上一页',
                nextPageText			: '下一页',
                nextPageTipText			: '下一页',
                totalPageBeforeText		: '共',
                totalPageAfterText		: '页',
                currPageBeforeText		: '当前第',
                currPageAfterText		: '页',
                totalInfoSplitStr		: '/',
                totalRecordsBeforeText	: '共',
                totalRecordsAfterText	: '条数据',
                gopageBeforeText		: '&nbsp;转到',
                gopageButtonOkText		: '确定',
                gopageAfterText			: '页',
                buttonTipBeforeText		: '第',
                buttonTipAfterText		: '页'
            }
        });

    });

    function deleteActivity(id) {
        $.ajax({
            type:'post',
            url:'delete',
            data:{
                'id':id
            },
            success:function () {
                location.reload();
            }
        })
    }
    //状态更改为2
    function publish(id) {
        $.ajax({
            url:'change-status?id='+id,
            success:function () {
                location.reload();
                alert('发布成功');
            }
        })
    }
    //状态更改为1,未发布
    function cancelPublish(id){
        $.ajax({
            url:'change-two?id='+id,
            success:function () {
                location.reload();
                alert('取消成功');
            }
        })
    }

    function signIn() {
        location.href='sign';
    }
    $('#publish').click(function () {
        location.href = "publish";
    });
    function myClick1(num) {
        if (num == 0) {
            location.href = "./?status=0";
//            $(this).css('color','#ff7614');
        } else if (num == 1) {
            location.href = "./?status=1";
        } else if (num == 2) {
            location.href = "./?status=2";
        } else if (num == 3) {
            location.href = "./?status=3";
        }
    }
</script>

